package reflection.proxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * @author DuJiabao
 * @create 2021-01-12 22:51
 */
public class MyInvocationHandler implements InvocationHandler {
    private Object obj;

    public MyInvocationHandler() {
    }

    public MyInvocationHandler(Object obj) { // 一开始就绑定,应该也可以吧
        this.obj = obj;
    }

    public void bind(Object obj) {
        this.obj = obj;  //绑定被代理类
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        return method.invoke(obj, args);
    }
}
